<template>
  <div class="base" v-if="showLogin">
     <div class="a">
    <div class="a1" v-for="(item,index) in list" :key="index" :style="{ height: (index %2  === 0) ? '20px' : '30px', width: (index % 2=== 0) ? '20px' : '30px' }">{{item}}</div>
  </div>
    <div class="auth-container">
      <div class="auth-card">
        <div class="header">
          <h1>欢迎使用</h1>
          <p>请登录或注册您的账户</p>
        </div>
        
        <div class="tabs">
          <button 
            :class="['tab', { 'active': activeTab === 'login' }]" 
            @click="activeTab = 'login'"
          >
            登录
          </button> 
          <button 
            :class="['tab', { 'active': activeTab === 'register' }]" 
            @click="activeTab = 'register'"
          >
            注册
          </button>
        </div>

        <!-- 登录表单 -->
        <form v-if="activeTab === 'login'" @submit.prevent="handleLogin" class="auth-form">
          <div class="form-group">
            <label for="login-email">邮箱</label>
            <input 
              type="email" 
              id="login-email" 
              v-model="loginEmail" 
              placeholder="请输入您的邮箱"
              required
            >
          </div>
          <div class="form-group">
            <label for="login-password">密码</label>
            <input 
              type="password" 
              id="login-password" 
              v-model="loginPassword" 
              placeholder="请输入密码"
              required
            >
          </div>
          <div class="form-group remember">
            <input type="checkbox" id="remember" v-model="rememberMe">
            <label for="remember">记住我</label>
            <a href="#" class="forgot-password">忘记密码?</a>
          </div>
          <button type="submit" class="auth-button">登录</button>
        </form>

        <!-- 注册表单 -->
        <form v-if="activeTab === 'register'" @submit.prevent="handleRegister" class="auth-form">
          <div class="form-group">
            <label for="register-email">邮箱</label>
            <input 
              type="email" 
              id="register-email" 
              v-model="registerEmail" 
              placeholder="请输入您的邮箱"
              required
            >
          </div>
          <div class="form-group">
            <label for="register-password">密码</label>
            <input 
              type="password" 
              id="register-password" 
              v-model="registerPassword" 
              placeholder="设置密码 (至少8个字符)"
              required
              minlength="8"
            >
          </div>
          <div class="form-group">
            <label for="confirm-password">确认密码</label>
            <input 
              type="password" 
              id="confirm-password" 
              v-model="confirmPassword" 
              placeholder="请再次输入密码"
              required
            >
          </div>
          <div class="form-group terms">
            <input type="checkbox" id="terms" v-model="acceptTerms" required>
            <label for="terms">我已阅读并同意 <a href="#">服务条款</a> 和 <a href="#">隐私政策</a></label>
          </div>
          <button type="submit" class="auth-button">注册</button>
        </form>

        <div class="social-login">
          <p>或使用以下方式登录</p>
          <div class="social-icons">
            <button class="social-icon google">
              <i class="icon">G</i>
            </button>
            <button class="social-icon facebook">
              <i class="icon">f</i>
            </button>
            <button class="social-icon twitter">
              <i class="icon">t</i>
            </button>
          </div>
        </div>
      </div>
    </div>
  </div>
  
  <div v-else>
    <router-view />
  </div>
</template>

<script>
export default {
  name: 'LoginApp',
  data() {
    return {
       list: '12345678987654321',
      showLogin: true,
      activeTab: 'login', // 'login' 或 'register'
      loginEmail: '',
      loginPassword: '',
      rememberMe: false,
      registerEmail: '',
      registerPassword: '',
      confirmPassword: '',
      acceptTerms: false,
    }
  },
  methods: {
    handleLogin() {
      // 实际应用中这里会有API调用
      if (this.loginEmail && this.loginPassword) {
        this.login();
      } else {
        alert('请输入邮箱和密码');
      }
    },
    handleRegister() {
      if (!this.registerEmail) {
        alert('请输入邮箱');
        return;
      }
      
      if (this.registerPassword.length < 8) {
        alert('密码长度至少为8个字符');
        return;
      }
      
      if (this.registerPassword !== this.confirmPassword) {
        alert('两次输入的密码不一致');
        return;
      }
      
      if (!this.acceptTerms) {
        alert('请接受服务条款和隐私政策');
        return;
      }
      
      // 实际应用中这里会有API调用
      alert(`注册成功! 欢迎 ${this.registerEmail}`);
      this.reg();
    },
    login() {
      this.showLogin = false
      sessionStorage.setItem('showLogin', '0')
      this.$router.push('/Lingin-x')
    },
    reg() {
      this.showLogin = false
      sessionStorage.setItem('showLogin', '0')
      this.$router.push('/halo')
    }
  },
  mounted() {
    sessionStorage.getItem('showLogin') == '0' ? this.showLogin = false : this.showLogin = true
    
    this.$nextTick(() => {
      setTimeout(() => {
        if (this.$route.path === '/' || this.$route.path === '/login') {
          this.showLogin = true
          sessionStorage.setItem('showLogin', '1')
        }
      })
    })
  }
}
</script>

<style scoped>
/* 修改基础容器样式 */
.base {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
  overflow: hidden;
  z-index: 1000;
  padding: 0;
  margin: 0;
}

.auth-container {
  width: 100%;
  max-width: 450px;
  padding: 20px;
  z-index: 10;
  transform: translateY(-5%); /* 关键修改：向上偏移 */
}

.auth-card {
  background: white;
  border-radius: 16px;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.25);
  padding: 40px 30px;
  animation: fadeIn 0.6s ease-out;
}

.header {
  text-align: center;
  margin-bottom: 25px; 
}

.header h1 {
  color: #2c3e50;
  font-size: 28px;
   margin-bottom: 8px; 
}

.header p {
  color: #7f8c8d;
  font-size: 16px;
}

.tabs {
  display: flex;
  margin-bottom: 25px;
  border-bottom: 1px solid #eee;
}

.tab {
  flex: 1;
  padding: 15px 0;
  text-align: center;
  background: none;
  border: none;
  font-size: 18px;
  font-weight: 600;
  color: #777;
  cursor: pointer;
  position: relative;
  transition: color 0.3s;
}

.tab.active {
  color: #3498db;
}

.tab.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 100%;
  height: 3px;
  background: #3498db;
  border-radius: 3px 3px 0 0;
}

.auth-form {
   margin-top: 20px; 
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: #555;
  font-size: 14px;
}

.form-group input[type="email"],
.form-group input[type="password"] {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 16px;
  transition: border-color 0.3s;
  box-sizing: border-box;
}

.form-group input[type="email"]:focus,
.form-group input[type="password"]:focus {
  border-color: #3498db;
  outline: none;
  box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

.remember, .terms {
  display: flex;
  align-items: center;
  font-size: 14px;
  margin-top: 10px;
}

.remember input, .terms input {
  margin-right: 8px;
}

.forgot-password {
  margin-left: auto;
  color: #3498db;
  text-decoration: none;
  font-size: 14px;
}

.forgot-password:hover {
  text-decoration: underline;
}

.terms label {
  font-size: 14px;
  color: #666;
}

.terms a {
  color: #3498db;
  text-decoration: none;
}

.terms a:hover {
  text-decoration: underline;
}

.auth-button {
  width: 100%;
  padding: 14px;
  background: #3498db;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.3s;
  margin-top: 10px;
  box-shadow: 0 4px 6px rgba(50, 50, 93, 0.11), 0 1px 3px rgba(0, 0, 0, 0.08);
}

.auth-button:hover {
  background: #2980b9;
  transform: translateY(-2px);
}

.social-login {
  margin-top: 25px;
  text-align: center;
  padding-top: 20px;
  border-top: 1px solid #eee;
}

.social-login p {
  color: #777;
  margin-bottom: 15px;
  position: relative;
}

.social-icons {
  display: flex;
  justify-content: center;
  gap: 15px;
}

.social-icon {
  width: 45px;
  height: 45px;
  border-radius: 50%;
  border: 1px solid #ddd;
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s;
}

.social-icon:hover {
  transform: translateY(-3px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.social-icon.google:hover {
  background: #db4437;
  border-color: #db4437;
  color: white;
}

.social-icon.facebook:hover {
  background: #4267B2;
  border-color: #4267B2;
  color: white;
}

.social-icon.twitter:hover {
  background: #1DA1F2;
  border-color: #1DA1F2;
  color: white;
}

.icon {
  font-style: normal;
  font-weight: bold;
}

/* 动画效果 */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 背景装饰 */
.base::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
  transform: rotate(30deg);
  z-index: 1;
}
</style>

<style>
/* 全局样式 - 必须放在这里才能生效 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
}

#app {
  height: 100%;
  width: 100%;
}
.a {
    display: flex;
    /* flex-flow: column wrap; */
    flex-direction: row;
    flex-wrap: wrap; 
    width: 500px;
    height: 500px;
    background-color: antiquewhite;
}

.a1 {
    width: 20px;
    height: 20px;
    background-color: red;
    margin: 30px;
    color: #fff
}
</style>